package com.boomsecret.juc.locks;

import java.util.concurrent.locks.LockSupport;

/**
 * @author wangjinliang on 2019/1/18.
 */
public class LockSupportDemo {

    public static void main(String[] args) throws Exception {
        Thread t2 = new Thread() {
            @Override
            public void run() {
                System.out.println("t2 start");
                LockSupport.park(this);
                System.out.println("t2 sleep");
                try {
                    Thread.sleep(5000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("t2 end");
            }
        };

        Thread t1 = new Thread(() -> {
            System.out.println("t1 start");
            // notify
            LockSupport.unpark(t2);
            System.out.println("t1 end");
        });
        t2.start();
        Thread.sleep(2000);

        t1.start();
    }
}
